//
//  UIKitEx.swift
//  Loop
//
//  Created by remy on 2021/10/21.
//

import UIKit

public extension UIScreen {
    static var size: CGSize { UIScreen.main.bounds.size }
    
    static var width: CGFloat { UIScreen.main.bounds.size.width }
    
    static var height: CGFloat { UIScreen.main.bounds.size.height }
    
    static var center: CGPoint { CGPoint(x: UIScreen.main.bounds.midX, y: UIScreen.main.bounds.midY) }
}

public extension UIColor {
    convenience init(_ hexString: String, _ alpha: CGFloat = 1.0) {
        var string = ""
        if hexString.lowercased().hasPrefix("0x") {
            string = hexString.replacingOccurrences(of: "0x", with: "")
        } else if hexString.hasPrefix("#") {
            string = hexString.replacingOccurrences(of: "#", with: "")
        } else {
            string = hexString
        }
        if let hexValue = Int(string, radix: 16) {
            self.init(hexValue, alpha)
        } else {
            self.init(0x000000, alpha)
        }
    }
    
    convenience init(_ hex: Int, _ alpha: CGFloat = 1.0) {
        let red = (hex >> 16) & 0xff
        let green = (hex >> 8) & 0xff
        let blue = hex & 0xff
        self.init(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: alpha)
    }
}
